package com.boge.modules.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.boge.common.utils.ShiroUtils;
import com.boge.modules.sys.entity.SysUserEntity;
import com.boge.modules.sys.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boge.common.utils.PageUtils;
import com.boge.common.utils.Query;

import com.boge.modules.shop.dao.MemoDao;
import com.boge.modules.shop.entity.MemoEntity;
import com.boge.modules.shop.service.MemoService;


@Service("memoService")
public class MemoServiceImpl extends ServiceImpl<MemoDao, MemoEntity> implements MemoService {

    @Autowired
    private SysUserService userService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        IPage<MemoEntity> page = this.page(
                new Query<MemoEntity>().getPage(params),
                new LambdaQueryWrapper<MemoEntity>()
                        .eq(!"admin".equals(userEntity.getUsername()),MemoEntity::getUserId,userEntity.getUserId())
        );
        List<MemoEntity> records = page.getRecords();
        if(records != null){
            for (MemoEntity record : records) {
                SysUserEntity user = userService.getById(record.getUserId());
                record.setUserName(user.getUsername());
            }
        }

        return new PageUtils(page);
    }

}